<?php


namespace logic\cyf;


use frontend\models\cyf\FlashSale;
use frontend\models\cyf\Order;

class OrderLogic
{
    /**
     * 生成订单
     * @param $params
     * @return bool
     * @throws \Exception
     * @cyf
     */
    public static function createOrder($params)
    {
        $address = AddRessLogin::shippingAddRess($params['user_id']);//获取收货地址
        $killGoods = FlashSale::flashOne($params['id']);
        $order_no = 'seckill'.date('YmdHis').str_pad($params['user_id'],2,0,STR_PAD_LEFT);
//        $order = [
//            'order_no'=>$order_no,
//            'user_id'=>$params['user_id'],
//            'status'=>1,
//            'pay_status'=>0,
//            'distribution_status'=>0,
//            'accept_name'=>$address['accept_name'],
//            'postcode'=>$address['postcode'],
//            'telphone'=>$address['telphone'],
//            'countprovincery'=>$address['country'],
//            'province'=>$address['province'],
//            'city'=>$address['city'],
//            'area'=>$address['area'],
//            'address'=>$params['address'],
//            'mobile'=>$params['mobile'],//应付金额
//            'real_amount'=>'real_amount'//实付金额
//        ];
//        va($order_no);die();
        $order = [
            'order_no'=>$order_no,
            'user_id'=>$params['user_id'],
            'status'=>1,
            'pay_status'=>0,
            'real_amount'=>$killGoods['flash_price'],
        ];
        $res = Order::create($order);
        if(!$res) return false;
        return  \Yii::$app->db->getLastInsertID();

    }
}